<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css"/>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    姓名
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="username" type="text"
                           value="{$model['username']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    性别
                </label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" {if condition="$model.sex == '男'"} checked="" {/if}>
                    <input type="radio" name="sex" value="女" title="女" {if condition="$model.sex == '女'"} checked="" {/if}>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    班级ID
                </label>
                <div class="layui-input-block">
                    <select name="class_id">
                        {volist name="cla" id="vo"}
                        <option value="{$vo.id}" {if condition="$model.class_id == $vo.id"} selected {/if}>{$vo.class_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    身高
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="height" type="text"
                           value="{$model['height']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    体重
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="weight" type="text"
                           value="{$model['weight']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    头围
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="head_length" type="text"
                           value="{$model['head_length']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    生日
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="birthday" id="birthday"
                           value="{$model['birthday']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    入托时间
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="nursery_time" id="nursery_time"
                           value="{$model['nursery_time']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    到期时间
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="end_time" id="end_time"
                           value=""/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    家长电话
                </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input layui-form-danger" name="mobile" type="text"
                           value="{$model['mobile']??""}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    学生照片
                </label>
                <div class="layui-input-block">
                    <button class="pear-btn pear-btn-primary pear-btn-sm upload-image" type="button">
                        <i class="fa fa-image">
                        </i>
                        上传图片
                    </button>
                    <input name="student_img" type="hidden" value="{$model['body_img']??""}"/>
                    <div class="upload-image">
                        <span>
                        </span>
                        <img class="upload-image" src="{$model['body_img']??""}"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'jquery', 'layedit', 'uploads', 'laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layedit = layui.layedit
        let laydate = layui.laydate
        layedit.set({
            uploadImage: {
                url: "{$Request.root}/index/upload"
            }
        });

        //常规用法 end_time
        laydate.render({
            elem: '#nursery_time'
        });

        laydate.render({
            elem: '#end_time'
        });

        laydate.render({
            elem: '#birthday'
        });

        //建立编辑器

        form.on('submit(save)', function (data) {

            $.ajax({
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (res) {
                    //判断有没有权限
                    if (res && res.code == 999) {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 2000,
                        })
                        return false;
                    } else if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dataTable");
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>